package com.thousandsunny.auth;

import com.google.common.collect.Lists;
import com.thousandsunny.dal.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * @author Savitar
 */
@Service
public class DomainUserDetailsService implements UserDetailsService, Serializable {
    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return new com.thousandsunny.auth.UserDetails("savitar", new BCryptPasswordEncoder().encode("123456"), Lists.newArrayList(new SimpleGrantedAuthority("admin")));
    }
}
